<template>
	<view>
		<button class="c-btn"
		:class="type?'c-btn-'+type:''"
		:hover-class="hoverClass"
		:disabled="disabled"
		:hover-start-time="hoverStartTime"
		:hover-stay-time="hoverStayTime"
		:open-type="openType"
		>
			<c-loading v-if="loading" 
			:loading-type="loadingType" 
			:loading-color="loadingColor" 
			:loading-text-size="loadingTextSize" 
			:loading-text="loadingText"
			:loading-size="loadingSize">{{loadingText}}</c-loading>
			<slot />
		</button>
	</view>
</template>


<script>
	import {loading} from "../common/behaviors.js";
	export default {
		props:{
			type:{
				type:String,
				default:"default"
			},
			hoverClass:{
				type:String,
				default:"c-button-hover"
			},
			loading:{
				type:[String,Boolean],
				default:false
			},
			disabled:{
				type:Boolean,
				default:false
			},
			hoverStartTime:{
				type:[String,Number],
				default:20  //按住后多久出现点击态，单位毫秒
			},
			hoverStayTime:{
				type:[String,Number],
				default:70  //手指松开后点击态保留时间，单位毫秒
			},
			openType:{
				type:String,
			},
			...loading
		},
		data() {
			return {
				cBtnWidth:0
			}
		},
		created() {
			this.initBtn()
		},
		methods:{
			initBtn:function(){
				if(this.loading){
					this.cBtnWidth = parseInt(206) + parseInt(this.loadingSize);
				}else{
					this.cBtnWidth = parseInt(206)
				}
			},
		}
	}
</script>

<style scoped>
	.c-btn::after{
		content: " ";
		position: absolute;
		top: 50%;
		left: 50%;
		opacity: 0;
		width: 100%;
		height: 100%;
		border: inherit;
		border-color: #000;
		background-color: #000;
		border-radius: inherit;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%)
	}
	.c-btn{
		margin: 10rpx;
		position: relative;
		padding: 0;
		display: inline-block;
		width: auto;
		min-width: 103rpx;
		padding: 0 20rpx;
		height: 103rpx;
		line-height: 103rpx;
		border-radius: 4rpx;
		box-sizing: border-box;
		font-size: 32rpx;
		text-align: center;
		vertical-align: middle;
		-webkit-appearance: none;
		-webkit-text-size-adjust: 100%
	}
	.c-btn-default{
		color: #333;
		background-color: #fff;
		border: 2rpx solid #eee;
	}
	.c-btn-primary{
		color: #fff;
		background-color: #4b0;
		border: 2rpx solid #4b0;
	}
	.c-btn-info{
		color: #fff;
		background-color: #1989fa;
		border: 1px solid #1989fa;
	}
	.c-btn-warning{
		color: #fff;
		background-color: #ee0a24;
		border: 1px solid #ee0a24;
	}
	.c-btn-danger{
		color: #fff;
		background-color: #ff976a;
		border: 1px solid #ff976a;
	}
	.c-button-hover::after{
		content: " ";
		position: absolute;
		top: 50%;
		left: 50%;
		opacity: 0.15;
		width: 100%;
		height: 100%;
		border: inherit;
		border-color: #000;
		background-color: #000;
		border-radius: inherit;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%)
	}
</style>
